<?php 

 header("Content-type: text/html; charset=utf-8");
require("conn.php");//计分榜API

$data = $_POST['data'];
$data=json_decode($data,true);


$sql = "select * from user where 1=1";
$result = mysql_query($sql ,$conn);
$zhoubang = Array();
$k = 0;
while ($row=mysql_fetch_array($result)) {
	$zhoubang[$k]=$row;
	$k++;
}
$zhoubang = zhouBubbleSort($zhoubang);
$ribang = riBubbleSort($zhoubang);

$allbang = array('zhou'=>$zhoubang ,'ribang'=>$ribang );

echo  json_encode($allbang);

function zhouBubbleSort($arr){

    for ($i=0 ; $i <count($arr) ; $i++) { 

        $data = '';
        for ($j=$i ; $j < count($arr)-1 ; $j++) { 
            if ($arr[$i]['week'] < $arr[$j+1]['week']) {

                $data      = $arr[$i]; 
                $arr[$i]   = $arr[$j+1];
                $arr[$j+1] = $data; 
          }
        }
    }
  return $arr;
}

function riBubbleSort($arr){

    for ($i=0 ; $i <count($arr) ; $i++) { 

        $data = '';
        for ($j=$i ; $j < count($arr)-1 ; $j++) { 
            if ($arr[$i]['today'] < $arr[$j+1]['today']) {
                $data      = $arr[$i]; 
                $arr[$i]   = $arr[$j+1];
                $arr[$j+1] = $data; 
          }
        }
    }
  return $arr;
}











